//
//  RWSJViewController.m
//  VmiSJ
//
//  Created by Apple on 2017/1/10.
//  Copyright © 2017年 汪的一声就哭了！. All rights reserved.
//

#import "RWSJViewController.h"

@interface RWSJViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,strong) UITableView *tableView;

@end

@implementation RWSJViewController
{
    NSMutableArray *_listArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"完成时间";
    [self obtainListData];
    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT) style:UITableViewStylePlain];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    _tableView.backgroundColor = BackColor;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.view addSubview:_tableView];
    [_tableView registerNib:[UINib nibWithNibName:@"WCSJTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell1"];
}

//设置单元格高度
- (CGFloat)tableView:(UITableView *)atableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 44;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 20;
}
//设置表视图中的行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _listArray.count;
}

//设置单元格中的数据
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    WCSJTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell1"];
    cell.label.text = _listArray[indexPath.row];
    if ([_listArray[indexPath.row] isEqualToString:self.timeStr]) {
        cell.backImageView.hidden = NO;
    } else {
        cell.backImageView.hidden = YES;
    }
    cell.backgroundColor = [UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    for (NSInteger i = 0; i < _listArray.count; i++) {
        WCSJTableViewCell *cell = [tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];
        cell.backImageView.hidden = YES;
    }
    WCSJTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    cell.backImageView.hidden = NO;
    [self.delegate RWSJViewControllerSendType:_listArray[indexPath.row]];
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark -------------- 用户信息网络请求
- (void)obtainListData
{
    [NetRequiest handleDataWithString:[NSString stringWithFormat:@"%@",HTTPLOAD] dictionary:@{@"v1":@"taskfinishtime"} HUD:YES block:^(id responseObject) {
        if ([responseObject[@"code"] isEqual:@200]) {
            _listArray = [NSMutableArray array];
            for (NSDictionary *dic in responseObject[@"result"]) {
                [_listArray addObject:dic[@"time_length"]];
            }
            [self.tableView reloadData];
        } else {
            [[SQShowMessage shareMessage] showMessageWithStr:responseObject[@"msg"]];
        }
    }];
}

@end
